#include "RingBuffer.hpp"
#include <unistd.h>

using namespace RingBufferModule;

void *Product(void *args)
{
    int data = 0;
    RingBuffer<int> *bq = static_cast<RingBuffer<int> *>(args);
    while (1)
    {
        bq->Enqueue(data);
        std::cout<<"生产者生产了一个数据:"<<data++<<std::endl;
    }
}

void *Consum(void *args)
{
    RingBuffer<int> *bq = static_cast<RingBuffer<int> *>(args);
    int data;
    while (1)
    {
        sleep(2);
        bq->Pop(&data);
        std::cout<<"消费者消费了一个数据:"<<data<<std::endl;
    }
}


int main()
{
    RingBuffer<int> *bq = new RingBuffer<int>(5);
    pthread_t p1, c1;
    pthread_create(&p1,nullptr,Product,(void*)bq);
    pthread_create(&c1,nullptr,Consum,(void*)bq);

    pthread_join(p1,nullptr);
    pthread_join(c1,nullptr);

    return 0;
}
